﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AddIn.EA.Architecture.ComponentLogic.EAConverter
{
    public class EAConverterPackage : EAConverter
    {
        public override Framework.Common.IElement ConvertObject(ElementModel.BaseModel sourceElement, Framework.Common.IElement affectedElement)
        {
            //Validate element conversion types.
            if (!(sourceElement is ElementModel.Package))
                throw new InvalidOperationException("Invalid type. The source parameter \"sourceElement\" must be \"ElementModel.Package\" type.");
            if (!(affectedElement is Framework.Package) && !(affectedElement is Framework.Element))
                throw new InvalidOperationException("Invalid type. The source parameter \"affectedElement\" must be \"AddIn.EA.Framework.Package\" type.");

            //Create the typed local elements.
            ElementModel.Package package = sourceElement as ElementModel.Package;
            Framework.Package destinationElement = affectedElement as Framework.Package;

            Framework.Package packageEA = destinationElement.Packages.AddNew(package.Name);
            packageEA.Notes = package.Notes;

            packageEA.Update();

            return packageEA;
        }
    }
}
